import requests

CHECK_SSFW_URL = 'http://ssfw.hlju.edu.cn/ssfw/j_spring_ids_security_check'
SCORE_URL = 'http://ssfw.hlju.edu.cn/ssfw/zhcx/cjxx.do'
COURSES_URL = 'http://ssfw.hlju.edu.cn/ssfw/xkgl/xkjgcx.do'



def request_score(token):
    cookie = {'iPlanetDirectoryPro':token}
    req = requests.get(CHECK_SSFW_URL,cookies=cookie,allow_redirects=False)

    new_cookie = req.headers['Set-Cookie'].split(';')[0].split('=')[1]

    print('new cookie:',new_cookie)
    nc = {'JSESSIONID':new_cookie}

    nreq=requests.get(SCORE_URL,cookies=nc)

    print(nreq.headers)
    print(nreq.text)
    with open('scores.html', 'w') as f:
        f.write(nreq.text)



def request_course(token):
    cookie = {'iPlanetDirectoryPro':token}
    req = requests.get(CHECK_SSFW_URL,cookies=cookie,allow_redirects=False)

    new_cookie = req.headers['Set-Cookie'].split(';')[0].split('=')[1]

    print('new cookie:',new_cookie)
    nc = {'JSESSIONID':new_cookie}

    nreq=requests.get(COURSES_URL,cookies=nc)

    print(nreq.headers)
    print(nreq.text)

    with open('test.txt', 'w') as f:
        f.write(nreq.text)


if __name__=='__main__':
    request_score('AQIC5wM2LY4SfcyAmd%2Bgx6u1SLeCzQhh8W3vs1Mrl%2BDgabU%3D%40AAJTSQACMDI%3D%23')
